<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>

    /*
            第一种
     */
    let singleton = function () {
        // 私有变量和私有函数
        let privateVariable = 10;

        function privateFunction() {
            return false;
        }

        // 特权/公有方法和属性 
        return {
            publicProperty: true,
            publicMethod() {
                privateVariable++;
                return privateFunction();
            }
        };
    }();

    /*
        第二种:
        
     */
    let application = function () {
        // 私有变量和私有函数
        let components = new Array();
        // 初始化
        components.push(new BaseComponent())
        // 公共接口
        return {
            getComponentCount(){
                return components.length;
            },
            registerComponent(component){
                if(typeof component === 'object'){
                    components.push(component)
                }
            }
        }
    }();
</script>
</body>
</html>